import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_nav_bar/google_nav_bar.dart';
import 'package:line_icons/line_icons.dart';
import 'package:oli/pages/main/home/view.dart';
import 'package:oli/pages/main/mine/view.dart';

import 'logic.dart';

class MainPage extends StatelessWidget {
  const MainPage({super.key});

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<MainLogic>();
    final state = logic.state;
    return Scaffold(
      body: Obx(() {
        return IndexedStack(
          index: state.currentIndex.value,
          children: [const HomePage(), MinePage()],
        );
      }),
      bottomNavigationBar: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(blurRadius: 20, color: Colors.black.withOpacity(.1)),
          ],
        ),
        child: SafeArea(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 8),
            child: Obx(() {
              return Row(
                mainAxisAlignment: MainAxisAlignment.center, // 将 tabs 居中对齐
                children: [
                  GNav(
                    rippleColor: Colors.grey[300]!,
                    hoverColor: Colors.grey[100]!,
                    gap: 8,
                    activeColor: Colors.black,
                    iconSize: 24,
                    padding: const EdgeInsets.symmetric(
                      horizontal: 20,
                      vertical: 12,
                    ),
                    duration: const Duration(milliseconds: 400),
                    tabBackgroundColor: Colors.grey[100]!,
                    color: Colors.black,
                    tabs: [
                      const GButton(icon: LineIcons.home, text: '首页'),
                      const GButton(icon: LineIcons.meteor, text: '我的'),
                    ],
                    selectedIndex: state.currentIndex.value,
                    onTabChange: (index) {
                      state.currentIndex.value = index;
                    },
                  ),
                ],
              );
            }),
          ),
        ),
      ),
    );
  }
}
